package Model;

import java.util.Observable;

import Controller.App;
import Controller.EnumDirection;
import View.SpielerVC;
import View.WieseVC;

public class Spieler extends Observable {

	private int posX;
	private int posY;
	private App app;

	public Spieler(App app,int posX, int posY) {

		this.posX = posX;
		this.posY = posY;
		this.app=app;
		
	}

	public int getPosX() {
		return posX;
	}


	public int getPosY() {
		return posY;

	}


	public void move(EnumDirection dir) {

		switch (dir) {

		case NORTH:
			if(testeKollision(posX,posY-1)==true){
				break;
			}
			else{
				
			System.out.println("Laufe NORD");
			posY-=1;
			System.out.println("Model SpielerX:" +posX);
			System.out.println("Model SpielerY:" +posY);
			
			
			setChanged();
			break;}
		case SOUTH:
			if(testeKollision(posX,posY+1)==true){
				break;
			}
			else{
				System.out.println("Laufe SOUTH");
			posY+=1;
			System.out.println("Model SpielerX:" +posX);
			System.out.println("Model SpielerY:" +posY);
			setChanged();
			break;}
		case WEST:
			if(testeKollision(posX-1,posY)==true){
				break;
			}
			else{System.out.println("Laufe WEST");
			posX-=1;
			System.out.println("Model SpielerX:" +posX);
			System.out.println("Model SpielerY:" +posY);
			setChanged();
			break;}
		case EAST:
			if(testeKollision(posX+1,posY)==true){
				break;
			}
			else{System.out.println("Laufe EAST");
			posX+=1;
			System.out.println("Model SpielerX:" +posX);
			System.out.println("Model SpielerY:" +posY);
			setChanged();
			break;}
		}

		
		notifyObservers();
	}
	
	public boolean testeKollision(int xS,int yS){
		
		boolean kol=false;
		
		for(Hecke element:app.getWiese().getHeckenListe()){
			
			
			kol=element.contains(xS, yS);
			
			if(kol==true){
				System.out.println("HECKE");
				break;
			}
			
			
			
		}
		
		return kol;
	}
	
	}


